package OPTIONS

import (
	"github.com/astaxie/beego"
	"github.com/astaxie/beego/plugins/cors"
	"time"
)

type OPTIONS struct {
	beego.Controller
}

func (c *OPTIONS) OPTIONS() {
	//
	//defer func() {
	//	c.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Origin", "*")
	//	c.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Methods", "POST,OPTIONS,GET,DELETE,PUT")
	//	c.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Credentials", "true")
	//
	//	c.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Headers", "Content-Type,Authorization")
	//	c.Ctx.Output.Status = 200
	//	c.ServeJSON()
	//}()
	//
	//var mes *errorDeal2.Mes
	//
	//
	//c.Data["json"] = errorDeal.ErrLightMess(mes, "200", "success")
	//return

}

func CorsDomain() {
	//var time time.Duration
	beego.InsertFilter("*", beego.BeforeRouter, cors.Allow(&cors.Options{
		AllowAllOrigins: true,
		//AllowOrigins:	  []string{"Session"},
		AllowMethods:     []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
		AllowHeaders:     []string{"Origin", "Authorization", "Access-Control-Allow-Origin", "Access-Control-Allow-Headers", "Content-Type", "Session"},
		ExposeHeaders:    []string{"Content-Length", "Access-Control-Allow-Origin", "Access-Control-Allow-Headers", "Content-Type", "Session"},
		MaxAge:           10 * time.Minute.Round(time.Minute),
		AllowCredentials: true,
	}))
}
